package com.cysyz.web.modules.base.businesslog.domain;

import com.cysyz.mylib.domain.BaseEntity;
import com.cysyz.mylib.domain.annotation.Alias;
import com.cysyz.web.modules.base.businesslog.annotation.BusinessLogType;
import com.cysyz.web.modules.base.user.domain.SysUser;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.Type;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;


@Entity
@Table(name = "FNM_SYS_BUSINESS_LOG")
public class SysBusinessLog extends BaseEntity {
    private static final long serialVersionUID = 5454155825314635342L;

    //alias
    public static final String TABLE_ALIAS = "SysBusinessLog";
    public static final String ALIAS_BUSINESS_LOG_TYPE = "businessLogType";
    public static final String ALIAS_EXTRA_MESSAGE = "extraMessage";
    public static final String ALIAS_OPERATE_DATE = "operateDate";
    public static final String ALIAS_OPERATION_NAME = "operationName";

    //date formats
    public static final String FORMAT_OPERATE_DATE = DATE_TIME_FORMAT;


    //可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
    //columns START
    @Type(type="text")
    @Column(name = "EXTRA_MESSAGE")
    private String extraMessage;

    @Column(name = "BUSINESS_LOG_TYPE", unique = false, nullable = false, length = 10)
    @Alias(cn="业务类型")
    private BusinessLogType businessLogType;

    @Length(max=50)
    @Column(name = "OPERATION_NAME", unique = false, nullable = false, length = 50)
    @Alias(cn="业务名称")
    private String operationName;

    @OneToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "businessLog")
    private Set<SysBusinessLogTargetEntity> businessLogTargetEntitys = new HashSet(0);

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "OPERATE_DATE")
    private Date operateDate;

    @ManyToOne(cascade = {}, fetch = FetchType.LAZY)
    private SysUser operator;

    //columns END

    @Override
    public String[] businessKeys() {
        return new String[]{};
    }
    public BusinessLogType getBusinessLogType() {
        return this.businessLogType;
    }

    public void setBusinessLogType(BusinessLogType value) {
        this.businessLogType = value;
    }

    public String getOperationName() {
        return this.operationName;
    }

    public void setOperationName(String value) {
        this.operationName = value;
    }



    public void setBusinessLogTargetEntitys(Set<SysBusinessLogTargetEntity> businessLogTargetEntity){
        this.businessLogTargetEntitys = businessLogTargetEntity;
    }

    public Set<SysBusinessLogTargetEntity> getBusinessLogTargetEntitys() {
        return businessLogTargetEntitys;
    }









    public String toString() {
        return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
                .append("BusinessLogType",getBusinessLogType())
                .append("OperationName",getOperationName())
                .toString();
    }

    public Date getOperateDate() {
        return operateDate;
    }

    public void setOperateDate(Date operateDate) {
        this.operateDate = operateDate;
    }

    public SysUser getOperator() {
        return operator;
    }

    public void setOperator(SysUser operator) {
        this.operator = operator;
    }

    public String getExtraMessage() {
        return extraMessage;
    }

    public void setExtraMessage(String extraMessage) {
        this.extraMessage = extraMessage;
    }


    /*vo*/
    @Transient
    private String operatorName;

    @Transient
    private java.util.Date operateDateBegin;
    @Transient
    private java.util.Date operateDateEnd;


    public String getOperatorName() {
        return operatorName;
    }

    public void setOperatorName(String operatorName) {
        this.operatorName = operatorName;
    }

    public Date getOperateDateBegin() {
        return operateDateBegin;
    }

    public void setOperateDateBegin(Date operateDateBegin) {
        this.operateDateBegin = operateDateBegin;
    }

    public Date getOperateDateEnd() {
        return operateDateEnd;
    }

    public void setOperateDateEnd(Date operateDateEnd) {
        this.operateDateEnd = operateDateEnd;
    }
}

